home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / update~4.z / update~4 / lib_stdio_stdio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  5.2 KB  |  169 lines

  1. /*            s t d i o
  2.  *
  3.  *        Author: C. E. Chew
  4.  *        Date:   August 1989
  5.  *
  6.  * (C) Copyright C E Chew
  7.  *
  8.  * Feel free to copy, use and distribute this software provided:
  9.  *
  10.  *    1. you do not pretend that you wrote it
  11.  *    2. you leave this copyright notice intact.
  12.  *
  13.  * Definitions and user interface for the stream io package.
  14.  *
  15.  * Patchlevel 1.2
  16.  *
  17.  * Edit History:
  18.  * 06-Sep-1989    Cast (x) to (unsigned char) in call to _flsbuf().
  19.  * 05-Sep-1989  Mods for Gnu C (really for any ansi C) ++jrb
  20.  * 05-Sep-1989    Make self reliant by removing dependency on proto.h
  21.  *        and varargs.h.
  22.  * 04-Sep-1989    Undo change to putc() since it makes it so much
  23.  *        more complicated and makes so little difference
  24.  *        to the speed.
  25.  * 03-Sep-1989    Alter putc() to cope with line buffered streams.
  26.  *        This makes processing of line buffered streams
  27.  *        faster since no calls to _flsbuf is required
  28.  *        unless the buffer fills.
  29.  * 31-Aug-1989    Change to use _end as suggested by Bruce Evans
  30.  *        many moons ago.
  31.  */
  32.  
  33. #if    !defined(__STDIO__)
  34.  
  35. #define __STDIO__
  36.  
  37. #if    defined(__STDC__)
  38. #  if    !defined(__NO_PROTO__)
  39. #   define    __STDIO_P__(x)    x
  40. #  else
  41. #   define    __STDIO_P__(x)    ()
  42. #  endif
  43. #else
  44. # define    __STDIO_P__(x)    ()
  45. #endif
  46.  
  47. #define BUFSIZ 1024
  48. #define _NFILE 20
  49. #define NFILES _NFILE            /* backward compatibilty */
  50.  
  51. extern struct _iobuf {
  52.  unsigned char *_end;            /* point at end of buffer */
  53.  unsigned char *_ptr;            /* pointer into buffer */
  54.  unsigned char *_base;            /* base of buffer */
  55.  int _bufsiz;                /* size of buffer */
  56.  short _flag;                /* flags */
  57.  char _file;                /* channel number */
  58.  unsigned char _buf;            /* small buffer */
  59. } *_iop[_NFILE];
  60.  
  61. #define _IOFBF        0000        /* fully buffered io */
  62. #define _IOREAD        0001        /* opened for reading */
  63. #define _IOWRITE    0002        /* opened for writing */
  64. #define _IONBF        0004        /* unbuffered */
  65. #define _IOMYBUF    0010        /* allocated buffer */
  66. #define _IOEOF        0020        /* eof encountered */
  67. #define _IOERR        0040        /* error encountered */
  68. #define _IOSTRING    0100        /* strings */
  69. #define _IOLBF        0200        /* line buffered */
  70. #define _IORW        0400        /* opened for reading and writing */
  71.  
  72. #define SEEK_SET    0        /* seek from beginning */
  73. #define SEEK_CUR    1        /* seek from here */
  74. #define SEEK_END    2        /* seek from end */
  75.  
  76. #if defined(__STDC__)
  77. #  define NULL        ((void *)0L)    /* null pointer */
  78. #else
  79. #  define NULL        (0)        /* null pointer */
  80. #endif
  81. #define FILE        struct _iobuf    /* FILE structure */
  82. #define EOF        (-1)        /* eof flag */
  83.  
  84. #define stdin        (_iop[0])
  85. #define stdout        (_iop[1])
  86. #define stderr        (_iop[2])
  87.  
  88. #define getc(p)        ((p)->_ptr<(p)->_end?(int)(*(p)->_ptr++)\
  89.                         :_filbuf(p))
  90. #define getchar()    getc(stdin)
  91.  
  92. #define putc(x,p)    ((p)->_ptr<(p)->_end\
  93.                          ?(int)(*(p)->_ptr++=(unsigned char)(x))\
  94.                      :_flsbuf((unsigned char)(x),(p)))
  95. #define    putchar(x)    putc(x,stdout)
  96.  
  97. #define fileno(p)    ((p)->_file)
  98.  
  99. #define feof(p)        (((p)->_flag&_IOEOF)!=0)
  100. #define ferror(p)    (((p)->_flag&_IOERR)!=0)
  101. #define clearerr(p)    ((p)->_flag&=~(_IOEOF|_IOERR))
  102.  
  103. /* minix-ST gnu-c library specific -- defines CONST etc */
  104. #if defined(__GNUC__)
  105. #  if  !defined(__NO_PROTO__)
  106. #    include <std.h>
  107. #  endif
  108. #endif
  109.  
  110. #if !defined(CONST)
  111. #  define CONST    /* */
  112. #endif
  113.  
  114. int    _filbuf        __STDIO_P__((FILE *));
  115. int    _flsbuf        __STDIO_P__((unsigned char, FILE *));
  116.  
  117. FILE     *fopen        __STDIO_P__((CONST char *, CONST char *));
  118. FILE    *fdopen        __STDIO_P__((int, CONST char *));
  119. FILE    *freopen    __STDIO_P__((CONST char *, CONST char *, FILE *));
  120. int    fflush        __STDIO_P__((FILE *));
  121. int    fclose        __STDIO_P__((FILE *));
  122.  
  123. long    ftell        __STDIO_P__((FILE *));
  124. int    fseek        __STDIO_P__((FILE *, long, int));
  125. void    rewind        __STDIO_P__((FILE *));
  126.  
  127. int    fgetc        __STDIO_P__((FILE *));
  128. int    fputc        __STDIO_P__((int, FILE *));
  129. int    fread        __STDIO_P__((void *, unsigned int,
  130.                                      unsigned int, FILE *));
  131. int    fwrite        __STDIO_P__((CONST void *, unsigned int,
  132.                                      unsigned int, FILE *));
  133. int    getw        __STDIO_P__((FILE *));
  134. int    putw        __STDIO_P__((int, FILE *));
  135. char    *gets        __STDIO_P__((char *));
  136. char    *fgets        __STDIO_P__((char *, int, FILE *));
  137. int    puts        __STDIO_P__((CONST char *));
  138. int    fputs        __STDIO_P__((CONST char *, FILE *));
  139.  
  140. int    ungetc        __STDIO_P__((int, FILE *));
  141.  
  142. #if    !defined(__SRC__)
  143. int    printf        __STDIO_P__((CONST char *, ...));
  144. int    fprintf        __STDIO_P__((FILE *, CONST char *, ...));
  145. char *    sprintf        __STDIO_P__((char *, CONST char *, ...));
  146. int    scanf        __STDIO_P__((CONST char *, ...));
  147. int    fscanf        __STDIO_P__((FILE *, CONST char *, ...));
  148. int    sscanf        __STDIO_P__((CONST char *, CONST char *, ...));
  149. #else
  150. int    printf        __STDIO_P__((CONST char *, int));
  151. int    fprintf        __STDIO_P__((FILE *, CONST char *, int));
  152. char *    sprintf        __STDIO_P__((char *, CONST char *, int));
  153. int    scanf        __STDIO_P__((CONST char *, int));
  154. int    fscanf        __STDIO_P__((FILE *, CONST char *, int));
  155. int    sscanf        __STDIO_P__((CONST char *, CONST char *, int));
  156. #endif /* __SRC__ */
  157.  
  158. int    vprintf        __STDIO_P__((CONST char *, char *));
  159. int    vfprintf    __STDIO_P__((FILE *, CONST char *, char *));
  160. int    vsprintf    __STDIO_P__((char *, CONST char *, char *));
  161. int    vscanf        __STDIO_P__((CONST char *, char *));
  162. int    vfscanf        __STDIO_P__((FILE *, CONST char *, char *));
  163. int    vsscanf        __STDIO_P__((CONST char *, CONST char *, char *));
  164.  
  165. void    setbuf        __STDIO_P__((FILE *, char *));
  166. int    setvbuf        __STDIO_P__((FILE *, char *, int, unsigned int));
  167. #endif /* __STDIO__ */
  168.  
  169.